<template>
  <div>
    <el-table :data="store.getters['role/getRole']" border style="width: 100%">
      <el-table-column prop="id" label="角色编号" width="180" />
      <el-table-column prop="rolename" label="角色名称" width="180" />
      <el-table-column prop="status" label="状态">
        <template v-slot="item">
          <div>
            {{ item.row.status == 1 ? "启用" : "禁用" }}
          </div>
        </template>
      </el-table-column>
      <el-table-column prop="address" label="操作">
        <template v-slot="item">
          <el-button type="primary" size="small" @click="edit(item.row.id)"
            >编辑</el-button
          >
          <el-button type="danger" size="small" @click="del(item.row.id)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script lang="ts" setup>
import { defineEmits, ref } from "vue";
import { useStore } from "vuex";
import { roledelete } from "../../request/api";
import { ElMessage, ElMessageBox } from "element-plus";
let store = useStore();

// void:表示没有任何类型，一般用于定义方法的时候没有返回值。声明一个 void 类型的变量没有什么大用，因为你只能为它赋予 undefined 和 null。
let emit = defineEmits<{
  (e: "edit", value: "number"): void;
}>();

// 封装编辑
const edit = (id: number) => {
  emit("edit", id);
};

// 删除
const del = (id: number) => {
  ElMessageBox.confirm("你确定要离开我吗", {
    confirmButtonText: "确定",
    cancelButtonText: "取消",
    type: "warning",
  })
    .then(() => {
      roledelete({ id }).then((res) => {
        if (res.code == 200) {
          console.log(res);
          store.dispatch("role/getActionsRole");
        }
        ElMessage({
          type: "success",
          message: res.msg,
        });
      });
    })
    .catch(() => {
      ElMessage({
        type: "info",
        message: "您取消了删除",
      });
    });
};

// 调用role仓库
// store.dispatch('role/getActionsRole')
</script>

<style lang="less" scoped></style>
